// pages/goodsaddress/goodsaddress.js
let app = getApp();
let testAddr = app.globalData.testAddr;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    guestID: "",
    addrs:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.queryAddress();
  },
  queryAddress(){
    let that = this;
    let user = wx.getStorageSync("list");
    console.log(JSON.stringify(user));
    that.setData({
      guestID: user.guestid
    });
    app.util.request({
      url: testAddr + "receiver_address/getDetail?guestID="+that.data.guestID,
      method: "POST",
      success: function (res) {
        console.log(JSON.stringify(res.data));
        that.setData({
          addrs:res.data
        });
      },
      fail: function (res) {
        
      },
      complete: function (res) {

      },
    });
  },
  jumpAdd:function(){
    let that=this;
    wx.navigateTo({
      url: '../../pages/addrecaddr/addrecaddr?guestID='+that.data.guestID,
    })
  },
  delAddr(event){
    let that=this;
    var raId = event.currentTarget.dataset.raid;
    console.log(raId);
    wx.showModal({
      title: '删除',
      content: '确认删除此地址吗',
      success: function (res) {
        if (res.confirm) {
          app.util.request({
            url: testAddr + "receiver_address/removeByID?raID=" + raId,
            method: "POST",
            success: function (res) {
              console.log(JSON.stringify(res.data));
              wx.showToast({
                title: '删除成功',
                icon:"none"
              });
              that.queryAddress();
            },
            fail: function (res) {

            },
            complete: function (res) {

            },
          });
        } else {
        
        }
      }
    })
    
  },
  updateAddr(event){
    let that = this;
    var raId = event.currentTarget.dataset.raid;
    wx.navigateTo({
      url: '../../pages/addrecaddr/addrecaddr?guestID=' + that.data.guestID + "&raId=" + raId,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})